<template>
	<view class="main" @touchmove.stop.prevent="() => {}" :style="allStyle()">
		<!-- 选择器 -->
		<u-picker :show="showa" :columns="columnsa" keyName="name" @confirm="getStatusXC" @close="showa=false"
			@cancel="showa=false" closeOnClickOverlay></u-picker>
		<u-picker :show="showb" :columns="columnsb" keyName="name" @confirm="getStatusFK" @close="showb=false"
			@cancel="showb=false" closeOnClickOverlay></u-picker>
		<!-- 头部信息 -->
		<view class="having" style="height: 50px;">
			<view class="top-a"
				style="height: 50px;padding: 0px 10px;display: flex;align-items: center;justify-content: space-between;">
				<view class="top-left" style="display: flex;align-items: center;">
					<view class="aaa" v-show="zdPower || jbPower || shPower" style="display: flex;align-items: center;">
						<view style="font-size: 12px;">
							巡查：
						</view>
						<view @click="getXCPro()" class="top-check"
							style="width: 65px;height: 30px;;border-radius: 5px;border: 0.5px #e7e6e4 solid;background-color: #FFF;display: flex;justify-content: space-between;align-items: center;padding: 0px 5px;margin-right: 10px;">
							<view class="choose" style="font-size: 12px;color: #FF5500;">
								{{ taga }}
							</view>
							<u-icon name="arrow-down" size="12"></u-icon>
						</view>
					</view>
					<view class="bbb" style="display: flex;align-items: center;">
						<view style="font-size: 12px;">
							反馈：
						</view>
						<view @click="getFKPro()" class="top-check"
							style="width: 65px;height: 30px;;border-radius: 5px;border: 0.5px #e7e6e4 solid;background-color: #FFF;display: flex;justify-content: space-between;align-items: center;padding: 0px 5px;">
							<view class="choose" style="font-size: 12px;color: #FF5500;">
								{{ tagb }}
							</view>
							<u-icon name="arrow-down" size="12"></u-icon>
						</view>
					</view>
				</view>
				<view class="top-right" v-show="(zdPower || jbPower || shPower)">
					<u-button v-show="(zdPower || jbPower || shPower)" @click="jump('新增',0)" text="新 增" color="#FF5500"
						style="width: 60px;height: 30px;"></u-button>
				</view>
			</view>
		</view>
		<div><u-line></u-line></div>
		<!-- 空信息 -->
		<view class="noSearch" v-show="projectList.length==0">
			<div style="height: 100px;"></div>
			<view class="a" v-show="!isOk">
				<div style="height: 100px;"></div>
				<u-loading-icon mode="circle" size="50px"></u-loading-icon>
			</view>
			<view class="b" v-show="isOk">
				<view class="ccccccc" v-show="!notQx">
					<u-empty mode="search" text="暂无数据"></u-empty>
				</view>
				<view class="ddddddd" v-show="notQx">
					<u-empty mode="page" text="加载失败"></u-empty>
				</view>
			</view>
		</view>
		<!-- 删除模态框 -->
		<u-modal :show="showd" title="是否确认删除" showCancelButton @confirm="deletePross" @cancel="showd=false"></u-modal>
		<!-- 内容主体 -->
		<view class="content" v-show="projectList.length!=0">
			<view v-show="isXC" class="content-a" :style="getHeight()">
				<u-list :lowerThreshold="10" @scrolltolower="scrolltolower()" :style="getHei()">
					<u-list-item v-for="(item,index) in projectList" :key="index"
						style="background-color: #FFFFFF;padding: 10px 10px 0px 10px;">
						<view class="u-top"
							style="display: flex;justify-content: space-between;align-items:flex-start;">
							<view class="u-top-left" style="width: 70vw;font-weight: 800;">
								{{ item.xmmc }}
							</view>
							<view class="u-top-right">
								<view class="a" :style="getXCStyle(item.zgztn)">
									{{ item.zgztn }}
								</view>
								<view v-if="item.fkztn!=''" class="b" :style="getFKStyle(item.fkztn)">
									{{ item.fkztn }}
								</view>
								<view v-if="item.sfth && item.sfth==1" class="b" :style="getFKStyle('已退回')">
									{{ '已退回' }}
								</view>
							</view>
						</view>
						<view class="u-middle" style="margin-top: 5px;">
							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="account" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.trbm }}
								</view>
							</view>
							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="setting" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.jsdw }}
								</view>
							</view>
							<view class="m-2" style="display: flex;align-items: center;">
								<u-icon name="clock" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-2-2" style="color: #999;font-size: 14px;">
									{{ item.zdsjt }}
								</view>
							</view>
						</view>
						<view class="u-bottom"
							style="margin-top: 5px;display: flex;justify-content: flex-end;align-items: center;">
							<!-- <view class="u-b-1" v-show="item.zgzt==2 && zdPower && !jbPower && !shPower && user==item.createdBy" style="display: flex;align-items: center;">
								<u-button @click="editPro(item.id,1)" color="#FF5500" style="width: 60px;height: 30px;margin-right: 5px;" text="编 辑"></u-button>
								<u-button @click="deletePro(item.id)" color="#FF5500" plain style="width: 60px;height: 30px;margin-left: 5px;" text="删 除"></u-button>
							</view> -->
							<view class="u-b-1" v-show="item.zgzt==2" style="display: flex;align-items: center;">
								<u-button v-show="jbPower" color="#FF5500" style="width: 60px;height: 30px;" text="经 办"
									@click="goTo('经办',item.id,2)"></u-button>
								<u-button v-show="item.zgzt!=4 && (zdPower)" @click="editPro(item.id,2)" color="#FF5500"
									plain style="width: 60px;height: 30px;margin-left: 5px;" text="编 辑"></u-button>
								<u-button v-show="item.zgzt!=4 && (zdPower || jbPower || shPower)"
									@click="deletePro(item.id)" color="#FF5500" plain
									style="width: 60px;height: 30px;margin-left: 5px;" text="删 除"></u-button>
							</view>
							<view class="u-b-1" v-show="item.zgzt==3" style="display: flex;align-items: center;">
								<u-button v-show="shPower" color="#FF5500" style="width: 60px;height: 30px;" text="审 核"
									@click="goTo('审核',item.id,3)"></u-button>
								<u-button v-show="item.zgzt!=4 && (jbPower)" @click="editPro(item.id,3)" color="#FF5500"
									plain style="width: 60px;height: 30px;margin-left: 5px;" text="编 辑"></u-button>
								<u-button v-show="item.zgzt!=4 && (jbPower || shPower)" @click="deletePro(item.id)"
									color="#FF5500" plain style="width: 60px;height: 30px;margin-left: 5px;"
									text="删 除"></u-button>
							</view>
							<view class="u-b-1" v-show="item.zgzt==4">
								<u-button color="#FF5500" style="width: 60px;height: 30px;" text="导 出"
									@click="exportPros(item.id)"></u-button>
							</view>
							<view class="u-b-public" style="display: flex;align-items: center;">
								<u-button @click="jumpToDetail(item.id,item.xmmc)"
									style="width: 60px;height: 30px;margin-left: 5px;" text="详 情"></u-button>
							</view>
						</view>
						<div style="margin-top: 10px;"><u-line></u-line></div>
					</u-list-item>
				</u-list>
			</view>

			<view v-show="isFK" class="content-b" :style="getHeight()">
				<u-list :lowerThreshold="10" @scrolltolower="scrolltolower()" :style="getHei()">
					<u-list-item v-for="(item,index) in projectList" :key="index"
						style="background-color: #FFFFFF;padding: 10px 10px 0px 10px;">
						<view class="u-top"
							style="display: flex;justify-content: space-between;align-items:flex-start;">
							<view class="u-top-left" style="width: 70vw;font-weight: 800;">
								{{ item.xmmc }}
							</view>
							<view class="u-top-right">
								<view v-if="item.fkztn!=''" class="b" :style="getFKStyle(item.fkztn)">
									{{ item.fkztn }}
								</view>
							</view>
						</view>
						<view class="u-middle" style="margin-top: 5px;">
							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="account" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.trbm }}
								</view>
							</view>
							<view class="m-1" style="display: flex;align-items: center;">
								<u-icon name="setting" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-1-2" style="color: #999;font-size: 14px;">
									{{ item.jsdw }}
								</view>
							</view>
							<view class="m-2" style="display: flex;align-items: center;">
								<u-icon name="clock" color="#999" size="14"
									style="margin-top: 1px;margin-right: 2px;"></u-icon>
								<view class="m-2-2" style="color: #999;font-size: 14px;">
									{{ item.zdsjt }}
								</view>
							</view>
						</view>
						<view class="u-bottom"
							style="margin-top: 5px;display: flex;justify-content: flex-end;align-items: center;">
							<view class="u-b-1" v-show="item.fkzt==0">
								<u-button color="#FF5500" style="width: 60px;height: 30px;" text="反 馈"
									@click="goToFK(item.id)"></u-button>
							</view>
							<view class="u-b-1" v-show="item.fkzt==1">
								<u-button color="#FF5500" style="width: 60px;height: 30px;" text="导 出"
									@click="exportPros(item.id)"></u-button>
							</view>
							<view class="u-b-public" style="display: flex;align-items: center;">
								<u-button @click="jumpToDetail(item.id,item.xmmc)"
									style="width: 60px;height: 30px;margin-left: 5px;" text="详 情"></u-button>
							</view>
						</view>
						<div style="margin-top: 10px;"><u-line></u-line></div>
					</u-list-item>
				</u-list>
			</view>
		</view>
	</view>
</template>

<script>
	import croods from '@/common/croods-1.3.3.js';
	window.croods = croods;
	window.hydra = require('../../../common/wst_hydra-1.0.0.js');


	import coordtransform from 'coordtransform';
	import {
		proList,
		getDateDic,
		deletePro,
		exportPro
	} from '@/common/api.js'
	export default {
		onLoad: function(option) {
			this.$nextTick(() => {
				if (option.id != 0) {
					this.user = option.user
					if (option.zd == "true") {
						this.zdPower = true
					}
					if (option.jb == "true") {
						this.jbPower = true
					}
					if (option.sh == "true") {
						this.shPower = true
					}
				}
			})
		},
		onShow() {
			this.columnsa = []
			this.projectList = []
			this.isOk = false
			this.notQx = false
			this.getDic()
			/* await this.getData() */
			this.intervalId = setInterval(this.getNewData, 600000);

		},
		onUnload() {
			clearInterval(this.intervalId);
		},
		data() {
			return {
				user: '',
				zdPower: false,
				jbPower: false,
				shPower: false,
				/* 字典 */
				dic: {
					status: 'Enabled',
					type: 'PROJECT_ZGZT'
				},
				dicList: [],
				/* 头部信息 */
				isXC: false,
				isFK: false,
				/* 选择器 */
				showa: false,
				showb: false,
				taga: '全部',
				tagb: '全部',
				columnsa: [],
				columnsb: [
					[{
						name: '全部',
						value: '',
					}, {
						name: '未反馈',
						value: 0
					}, {
						name: '已反馈',
						value: 1
					}]
				],
				/* 请求 */
				query: {
					pageNum: 1,
					pageSize: 20,
					zgzt: '',
					fkzt: ''
				},
				projectList: [],
				isOver: false,
				showd: false,
				deleteid: '',
				oneStatus: false,
				isOk: false,
				intervalId: null,
				notQx: false,
				backShow: false,
				back: {
					id: '',
					thyy: ''
				}
			}
		},
		methods: {
			getDic() {
				getDateDic(this.dic).then(res => {
					this.dicList = res
					let temp = []
					temp.push({
						name: '全部',
						code: ''
					})
					temp = temp.concat(res)
					this.columnsa.push(temp)
					this.getData()
				})
			},
			getData() {
				proList(this.query).then(res => {
					if ("msgCode" in res && (res.msgCode == "1003" || res.msgCode == "-401")) {
						this.notQx = true
					} else {
						if (res.list.length == 0 && !this.oneStatus) {
							this.isXC = true
							this.oneStatus = true
						}
						if (res.list.length != 0) {
							this.oneStatus = true
							let temp = res.list[0]
							if (temp.zgzt != null) {
								this.isXC = true
							} else {
								this.isFK = true
							}
						}
						if (res.nextPage == 0) {
							this.isOver = true
						}
						const data = res.list.map(item => {
							item.fkztn = ''
							item.zgztn = ''
							if (item.zgzt != null) {
								const dateTemp = this.dicList.find(date => date.code === item.zgzt)
								if (dateTemp) {
									item.zgztn = dateTemp.name
								}
								if (item.zgzt == 4) {
									if (item.fkzt == 1) {
										item.fkztn = '已反馈'
									} else {
										item.fkztn = '未反馈'
									}
								}
							} else {
								if (item.fkzt == 1) {
									item.fkztn = '已反馈'
								} else {
									item.fkztn = '未反馈'
								}
							}
							let dateStr = item.zdsj
							let date = new Date(dateStr)
							let formattedDate = date.getFullYear() + '-' +
								('0' + (date.getMonth() + 1)).slice(-2) + '-' +
								('0' + date.getDate()).slice(-2) + ' ' +
								('0' + date.getHours()).slice(-2) + ':' +
								('0' + date.getMinutes()).slice(-2) + ':' +
								('0' + date.getSeconds()).slice(-2)
							item.zdsjt = formattedDate
							return item
						})
						if (this.projectList.length == 0) {
							this.projectList = data
						} else {
							data.forEach(temp => {
								let ishaving = this.projectList.find(zoo => zoo.id == temp.id)
								if (ishaving) {
									if (ishaving.zgzt != temp.zgzt || (ishaving.zgzt == 4 && temp.zgzt ==
											4 && ishaving.fkzt != temp.fkzt)) {
										let index = this.projectList.findIndex(test => test.id === ishaving
											.id);
										if (index !== -1) {
											this.projectList.splice(index, 1, temp);
										}
									}
								} else {
									this.projectList.push(temp)
								}
							})
						}
					}
					this.isOk = true
				})
			},
			/* 触底加载 */
			scrolltolower() {
				if (this.isOver) {
					return
				} else {
					this.query.pageNum += 1
					this.getData()
				}
			},
			/* 选择器 */
			getXCPro() {
				this.showa = true
			},
			getStatusXC(e) {
				this.taga = e.value[0].name
				this.query.zgzt = e.value[0].code
				this.projectList = []
				this.getData()
				this.showa = false
			},
			getFKPro() {
				this.showb = true
			},
			getStatusFK(e) {
				this.tagb = e.value[0].name
				this.query.fkzt = e.value[0].value
				this.projectList = []
				this.getData()
				this.showb = false
			},
			/* 删除 */
			deletePro(id) {
				this.showd = true
				this.deleteid = id
			},
			deletePross() {
				deletePro({
					id: this.deleteid
				}).then(res => {
					this.deleteid = ''
					this.showd = false
					this.projectList = []
					this.isOk = false
					this.getData()
				})
			},

			/* 导出 */
			exportPros(id) {
				exportPro({
					id: id
				}).then(res => {
					clearInterval(this.intervalId);
					let addr = res.url
					uni.navigateTo({
						url: `/pages/me/xmxc/pdfpop/index?addr=${addr}`
					})
				})
				/* let addr = 'http://10.10.34.229:8080/wst/static/tabBar/qq.pdf'
				uni.navigateTo({
					url:`/pages/me/xmxc/pdfpop/index?addr=${addr}`
				}) */
			},
			/* 样式 */
			allStyle() {
				let height = uni.getSystemInfoSync().windowHeight
				return {
					'height': height,
					'width': '100%'
				}
			},
			getHeight() {
				let height = uni.getSystemInfoSync().windowHeight - 50
				return {
					'height': height + 'px',
					'width': '100%',
					'display': 'flex',
					'flex-direction': 'column',
					'background-color': '#FAFAFA'
				}
			},
			getHei() {
				let height = uni.getSystemInfoSync().windowHeight - 50
				return {
					'height': height + 'px'
				}
			},
			getXCStyle(xc) {
				if (xc == '已审核') {
					return {
						'font-size': '14px',
						'color': '#53c21d'
					}
				} else {
					return {
						'font-size': '14px',
						'color': '#FF5500'
					}
				}
			},
			getFKStyle(fk) {
				if (fk == '已反馈') {
					return {
						'font-size': '14px',
						'color': '#53c21d'
					}
				} else {
					return {
						'font-size': '14px',
						'color': '#FF5500'
					}
				}
			},
			/* 定时刷新 */
			getNewData() {
				this.query.pageNum = 1
				proList(this.query).then(res => {
					if (res.nextPage == 0) {
						this.isOver = true
					}
					const data = res.list.map(item => {
						item.fkztn = ''
						item.zgztn = ''
						if (item.zgzt != null) {
							const dateTemp = this.dicList.find(date => date.code === item.zgzt)
							if (dateTemp) {
								item.zgztn = dateTemp.name
							}
							if (item.zgzt == 4) {
								if (item.fkzt == 1) {
									item.fkztn = '已反馈'
								} else {
									item.fkztn = '未反馈'
								}
							}
						} else {
							if (item.fkzt == 1) {
								item.fkztn = '已反馈'
							} else {
								item.fkztn = '未反馈'
							}
						}
						let dateStr = item.zdsj
						let date = new Date(dateStr)
						let formattedDate = date.getFullYear() + '-' +
							('0' + (date.getMonth() + 1)).slice(-2) + '-' +
							('0' + date.getDate()).slice(-2) + ' ' +
							('0' + date.getHours()).slice(-2) + ':' +
							('0' + date.getMinutes()).slice(-2) + ':' +
							('0' + date.getSeconds()).slice(-2)
						item.zdsjt = formattedDate
						return item
					})
					this.projectList = data
				})
			},
			/* 跳转 */
			jump(title, id) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xjxc/index?id=${id}&title=${title}`
				})
			},
			jumpToDetail(id, title) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xmxcxq/index?id=${id}&title=${title}`
				})
			},
			goTo(title, id, zgzt) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xcsc/index?id=${id}&title=${title}&zgzt=${zgzt}`
				})
			},
			editPro(id, zgzt) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/xcbj/index?id=${id}&zgzt=${zgzt}`
				})
			},
			goToFK(id) {
				clearInterval(this.intervalId);
				uni.navigateTo({
					url: `/pages/me/xmxc/fkxq/index?id=${id}`
				})
			}
		},
		async mounted() {

		}
	}
</script>

<style>
</style>